

#import <Foundation/Foundation.h>

#define _appCache    [AppCache sharedInstance]

extern NSString * const kGlobalInfo;    //!< 全局配置信息

@interface UserInfo : NSObject <NSCoding>
// MARK:通用个人信息Model,所有项目适用
@property (nonatomic, copy) NSString *account;      //!< 账号
@property (nonatomic, copy) NSString *password;     //!< 密码
@property (nonatomic, copy) NSString *userID;       //!< id
@property (nonatomic, copy) NSString *token;        //!< token
@property (nonatomic, copy) NSString *jpushTags;    //!< tag
@property (nonatomic, copy) NSString *jpushAlias;   //!< alias
@property (nonatomic, copy) NSString *mobile;       //!< 手机
@property (nonatomic, copy) NSURL    *avatarURL;    //!< 头像
@property (nonatomic, copy) NSString *nickName;     //!< 昵称
@property (nonatomic, copy) NSString *userName;     //!< 姓名
@property (nonatomic)       NSInteger sex;          //!< 性别(0.未知 1.男 2.女)
// MARK:业务信息Model,根据项目自行扩展
@end

@interface CityModel : NSObject <NSCoding>
@property (nonatomic, copy) NSString *cid;
@property (nonatomic, copy) NSString *code;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *pinYin;
@end

@interface AppCache : NSObject
/** 用户信息 */
@property (nonatomic, strong, readonly) UserInfo *userInfo;
/** 用户是否登录 */
@property (nonatomic, readonly) BOOL isLogin;
/** 是否检查过版本更新 */
@property (nonatomic) BOOL versionChecked;

+ (instancetype)sharedInstance;

/// 整个app生命周期中只请求一次数据并保存到内存中
/// 适用于数据变化不是很频繁的接口(比如全局配置),根据项目需求自行新增key和扩展方法实现
- (void)onceCacheForKey:(NSString *)key
                success:(void(^)(id responseObject))success
                failure:(void(^)(void))failure
                    hud:(BOOL)isHud;

/**
 更新缓存中个人信息
 @param json        信息数据
 @param reset       是否覆盖原始缓存(登录事件YES,其他NO)
 @param complete    回调
 */
- (void)updateUserInfo:(id)json reset:(BOOL)reset complete:(void(^)(void))complete;

/**
 清除缓存中个人信息
 常用于用户退出登录
 @param complete    回调
 */
- (void)clearUserInfo:(void(^)(void))complete;

/**
 实时加载用户的个人信息,从缓存中加载会影响正确性
 业务有需求比如个人积分、金额实时变动
 @param completion  回调(obj:数据,加载失败为nil)
 @param isHud       是否显示菊花
 */
- (void)refreshUserInfo:(void(^)(id obj))completion hud:(BOOL)isHud;

#pragma mark - 新功能引导
/** 功能引导 */
@property (nonatomic, strong, readonly) NSDictionary *guideInfo;

- (void)updateGuideInfo:(id)json complete:(void(^)(void))complete;

@end
